 /* This file is part of Stimer. Stimer - Simple reminder tool.
    Copyright (C) 2012  Klimov Max <cleemmi@gmail.com>

    Stimer is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    */
#include "reminder.h"
#include <QTimer>
#include <QTime>

Reminder::Reminder(QWidget *parent) :
    QWidget(parent)
{
    timer = new QTimer;
    startTime = QTime();
    timer->setSingleShot(true);
    connect(timer,SIGNAL(timeout()),this,SIGNAL(reminded()));
    time.setHMS(0,0,0,0);
}

void Reminder::setTime(const QTime &time)
{
    if (this->time==time||time.isNull()) return;
    timer->setInterval(QTime(0,0,0,0).msecsTo(time));
    this->time = time;
    emit timeChanged(this->time);
}

void Reminder::start()
{
    timer->stop();
    timer->start();
    startTime.start();
    emit started();
}

void Reminder::stop()
{
    timer->stop();
    startTime = QTime();
    emit stoped();
}

void Reminder::setMinutes(size_t value)
{
    QTime tmp(time.hour(),value,time.second(),time.msec());
    setTime(tmp);
}

void Reminder::setSeconds(size_t value)
{
    QTime tmp(time.hour(),time.minute(),value,time.msec());
    setTime(tmp);
}
